package test;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author MtRider
 * @version 1.0
 * @description IoDelete
 * @GiteeAndGithub MtRider
 * @date 2021/11/23 21:33
 */
public class IoDelete {

    public static void main(String[] args) throws UnsupportedEncodingException {
        PrintStream out = new PrintStream(System.out, true, "UTF-8");
        Scanner sc = new Scanner(System.in, "UTF-8");
        String str = sc.next();
        File rf = new File("filein.txt");
        File wf = new File("fileout.txt");
        String line;
        List<String> content = new ArrayList<>();
        try {
            FileReader fr = new FileReader(rf);
            BufferedReader bf = new BufferedReader(fr);
            try {
                line = bf.readLine();
                while (line != null) {
                    Pattern p = Pattern.compile(str, Pattern.CASE_INSENSITIVE);
                    Matcher matcher = p.matcher(line);
                    line = matcher.replaceAll("");
                    content.add(line);
                    line = bf.readLine();
                }
                FileWriter fw = new FileWriter(wf);
                BufferedWriter bw = new BufferedWriter(fw);
                for (String item : content) {
                    bw.write(item); //写数据
                    bw.newLine(); //跳到下一行
                }
                bw.flush();
                bw.close();
                bf.close();
                fr.close();
                fw.close();
            } catch (IOException e) {
                out.println("操作失败");
            }
        } catch (FileNotFoundException e) {
            out.println("没有找到该文件");
        }

    }
}
